using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DataTransferObject;
using DataAccess;

namespace DataAccess
{
   public  class clsChucVuDAO:clsDataAccessHelper 
    {

        // Fields
        private String tenTable;

        // Contructors
        public clsChucVuDAO()
        {
            this.tenTable = "CHUCVU";
        }
        #region Methods

       public int KiemTraMaCVXoaDuocKhong(clsChucVuDTO chuvu)
       {
           String sql;
           DataTable tbl;
           try
           {
               sql ="select MACV from NhanVien";
               tbl = new DataTable();
               tbl = this.ExecuteQuery(sql);

               int flag = 0;
               foreach (DataRow dr in tbl.Rows)
               {
                   string ma = dr["MaCV"].ToString().Trim();
                   if (ma == chuvu.MaCV)
                   {
                       flag = 1;
                   }
               }
               return flag;
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }

        //-------------------------------------Lấy dữ liệu bảng Chức vụ-----------------------

        public DataTable SelectAll()
        {
            String sql;
            DataTable dt;
            try
            {
                sql = "SELECT * FROM " + this.tenTable;
                dt = new DataTable();
                dt = this.ExecuteQuery(sql);

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
       //-----------------------------------------------------------------------------//


        //-------------------------------------Thêm vào bảng Chức Vụ-----------------------

       public bool Insert(clsChucVuDTO chucvu)
       {
           String sql;
           bool check = false;

           try
           {
               sql = "INSERT INTO " + this.tenTable;
               sql += " values('";
               sql += chucvu .MaCV + "',N'";
               sql += chucvu .TenCV + "')";
               check = this.ExecuteNonQuery(sql);

               return check;
           }
           catch(Exception ex)
           {
               throw ex;
           }
       }

        //-----------------------------------------------------------------------------//



       //-------------------------------------Xóa vào Chức vụ-----------------------
       public bool Delete(clsChucVuDTO chucvu)
       {
           String sql;
           bool check = false;

           try
           {
               sql = "DELETE ";
               sql += " FROM " + this.tenTable;
               sql += " WHERE MACV LIKE '" + chucvu .MaCV + "'";
               check = this.ExecuteNonQuery(sql);

               return check;
           }
           catch
           {
               return check;
           }
       }
       
    

       //-----------------------------------------------------------------------------//



       //-------------------------------------Sửa vào bảng Chức vụ-----------------------

       public bool Update(clsChucVuDTO chucvu)
       {
           String sql;
           bool check = false;

           try
           {
               sql = "UPDATE " + this.tenTable;
               sql += " SET";
               sql += " TENCV = N'";
               sql += chucvu .TenCV + "'";
               sql += " WHERE MACV LIKE '";
               sql += chucvu.MaCV  + "'";
               check = this.ExecuteNonQuery(sql);

               return check;
           }
           catch
           {
               return check;
           }
       }


       //-----------------------------------------------------------------------------//


        #endregion


    }
}
